import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
const store = new Vuex.Store({
  state: {
    allData:null,
    recommend: [],
    swipers: [],
    leftMenu: [],
    titles: [],
    contents: [],
    userInfo: [],
    skills: [],
    teach:[],
    ideas:[],
    tools:[]
  },
  mutations: {
    getAllData(state,res){
      state.allData=JSON.parse(JSON.stringify(res));
      state.swipers = JSON.parse(JSON.stringify(state.allData["swipers"]));
      state.recommend = JSON.parse(JSON.stringify(state.allData["recommend"]));
      state.leftMenu = JSON.parse(JSON.stringify(state.allData["leftMenu"]));
      state.titles = JSON.parse(JSON.stringify(state.allData["titles"]));
      state.contents = JSON.parse(JSON.stringify(state.allData["contents"]));
      state.skills = JSON.parse(JSON.stringify(state.allData["skills"]));
      state.ideas = JSON.parse(JSON.stringify(state.allData["ideas"]));
      state.userInfo = JSON.parse(JSON.stringify(state.allData["userInfo"]));
    },
  },
  actions: {
    //拿到所有的数据
    getAllData({commit}){
      fetch("./../src/data/works.json")
        .then(res => res.json())
        .then(res => {
          commit("getAllData", res);
        })
    }
  },
  getters: {

  }
})
export default store;
